﻿using DoddleReport;
using DoddleReport.Web;
using R.DMS.Data;
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Web;

namespace R.DMS.UI.Web
{
    /// <summary>
    /// 调用格式 PatentReport.ashx?ReportType=Excel
    /// </summary>
    public class PatentReport : WebReport
    {

        public override string FileName
        {
            get { return "专利统计总表" + DateTime.Now.Year; }
        }

        public override void CustomizeReport(Report report)
        {
            // Text Fields
            report.TextFields.Title = "专利统计总表";
            //report.TextFields.Footer = "Copyright 2009 &copy; The Doddle Project";
            //report.TextFields.Header = string.Format("Report Generated: {0}", DateTime.Now);

            //// Data Fields
            //report.DataFields["ProductID"].Hidden = true;
            //report.DataFields["CategoryID"].Hidden = true;
            //report.DataFields["SupplierID"].Hidden = true;
        }

        public override IReportSource ReportSource
        {
            get
            {
                CommonBusiness service = new CommonBusiness();
                var list = service.GetPatentList(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, DateTime.Now.Year.ToString());

                List<ExpandoObject> data = new List<ExpandoObject>();
                int seq = 0;
                foreach (var patent in list)
                {
                    dynamic item = new ExpandoObject();

                    seq++;
                    item.序号 = seq.ToString();
                    item.专利名称 = patent.Pa_PatentName;
                    item.专利人员 = patent.Pa_PatentUser;
                    item.专利类型 = patent.Pa_PatentTypeDesc;
                    item.专利号 = patent.Pa_PatentNo;
                    item.申请日期或发布日期 = patent.Pa_ApplyDate.ToString("yyyy.MM.dd");
                    item.状态 = patent.Pa_StatusDesc;
                    item.是否代理 = patent.Pa_ProxyFlagDesc;

                    data.Add(item);
                }
                return data.ToReportSource();
            }
        }
    }
}